/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import controlador.ControlLaberinto;
import javax.swing.JLabel;

/**
 *
 * @author ArandiLopez
 */
public class LaberintoVista extends javax.swing.JDialog {

    //Variable de la clase
    public static final int FILAS = 15, COLUMNAS = 15;
    JLabel[][] matrix;
    ControlLaberinto controlLaberinto;
    String tipo;

    /**
     * Creates new form LaberintoVista
     */
    public LaberintoVista(java.awt.Frame parent, boolean modal, String tipo) {
        super(parent, modal);
        this.tipo = tipo;
        setLayout(null);
        controlLaberinto = new ControlLaberinto();
        matrix = new JLabel[FILAS][COLUMNAS];

        for (int i = 0; i < FILAS; i++) {
            for (int j = 0; j < COLUMNAS; j++) {
                matrix[i][j] = new JLabel();
                matrix[i][j].setBounds(20 + j * 30, 50 + i * 30, 30, 30);
                add(matrix[i][j]);
            }
        }
        initComponents();
        if(tipo.equals("aleatorio")){
            controlLaberinto.crearMatrixAleatorio(matrix);
        }else{
            if(tipo.equals("predefinido")){
                nuevoJuegoBtn.setVisible(false);
                controlLaberinto.crearMatrizPredefinido(matrix);
                
            }
        }
        //
     }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nuevoJuegoBtn = new javax.swing.JButton();
        resolverBtn = new javax.swing.JButton();
        pantallaInicialBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        solucionTextArea = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        movimientoTextArea = new javax.swing.JTextArea();
        laberintoPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lblPruebas = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        nuevoJuegoBtn.setText("Nuevo Juego");
        nuevoJuegoBtn.setToolTipText("Nuevo Juego");
        nuevoJuegoBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevoJuegoBtnActionPerformed(evt);
            }
        });

        resolverBtn.setText("Resolver");
        resolverBtn.setToolTipText("Resolver este laberinto");
        resolverBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resolverBtnActionPerformed(evt);
            }
        });

        pantallaInicialBtn.setText("Pantalla Inicial");
        pantallaInicialBtn.setToolTipText("Regresar a la pantalla de inicio");
        pantallaInicialBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pantallaInicialBtnActionPerformed(evt);
            }
        });

        solucionTextArea.setEditable(false);
        solucionTextArea.setColumns(20);
        solucionTextArea.setRows(5);
        jScrollPane1.setViewportView(solucionTextArea);

        movimientoTextArea.setEditable(false);
        movimientoTextArea.setColumns(20);
        movimientoTextArea.setRows(5);
        jScrollPane2.setViewportView(movimientoTextArea);

        laberintoPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        javax.swing.GroupLayout laberintoPanelLayout = new javax.swing.GroupLayout(laberintoPanel);
        laberintoPanel.setLayout(laberintoPanelLayout);
        laberintoPanelLayout.setHorizontalGroup(
            laberintoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 466, Short.MAX_VALUE)
        );
        laberintoPanelLayout.setVerticalGroup(
            laberintoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 464, Short.MAX_VALUE)
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Solucion");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Movimiento");

        jLabel3.setFont(new java.awt.Font("Cantarell", 1, 24)); // NOI18N
        jLabel3.setText("Laberinto");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nuevoJuegoBtn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(resolverBtn))
                            .addComponent(laberintoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(pantallaInicialBtn))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblPruebas, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel3)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
                            .addComponent(jScrollPane2))
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(lblPruebas, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(laberintoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(resolverBtn)
                            .addComponent(nuevoJuegoBtn)
                            .addComponent(pantallaInicialBtn))
                        .addContainerGap(43, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void pantallaInicialBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pantallaInicialBtnActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_pantallaInicialBtnActionPerformed

    private void nuevoJuegoBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevoJuegoBtnActionPerformed
        // TODO add your handling code here:
        this.controlLaberinto = new ControlLaberinto();
        movimientoTextArea.setText("");
        solucionTextArea.setText("");
        controlLaberinto.crearMatrixAleatorio(matrix);
    }//GEN-LAST:event_nuevoJuegoBtnActionPerformed

    private void resolverBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resolverBtnActionPerformed
        // TODO add your handling code here:
        //Es aui donde se anadira la parte de la resolucion
        if(tipo.equals("aleatorio")){
            controlLaberinto.controlCaminoAleatorio();
        }else{
            if (tipo.equals("predefinido")){
                controlLaberinto.controlCaminoPredefinido();
            }
        }
    }//GEN-LAST:event_resolverBtnActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /*
//         * Set the Nimbus look and feel
//         */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /*
//         * If Nimbus (introduced in Java SE 6) is not available, stay with the
//         * default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(LaberintoVista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(LaberintoVista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(LaberintoVista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(LaberintoVista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /*
//         * Create and display the dialog
//         */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                LaberintoVista dialog = new LaberintoVista(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public String getTipo() {
        return tipo;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel laberintoPanel;
    private javax.swing.JLabel lblPruebas;
    private javax.swing.JTextArea movimientoTextArea;
    private javax.swing.JButton nuevoJuegoBtn;
    private javax.swing.JButton pantallaInicialBtn;
    private javax.swing.JButton resolverBtn;
    private javax.swing.JTextArea solucionTextArea;
    // End of variables declaration//GEN-END:variables
}
